package com.song.mall.search.controller;

import com.song.mall.search.service.MallSearchService;
import com.song.mall.search.vo.SearchParam;
import com.song.mall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 宋超
 * HP - the login name of the current user.
 * 2021/9/26 - the current system date.
 * 17:33 - the current system time.
 */
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    @GetMapping("list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request){
        param.set_queryString(request.getQueryString());
        //System.out.println("hello");
        //根据页码 传来的页面参数，去es中检索商品
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result",result);
        return "list";
    }
}
